package com.atguigu.spzx.order.mapper;

import com.atguigu.spzx.order.entity.OrderInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;

/**
 * <p>
 * OrderInfoMapper
 * </p>
 *
 * @author flyduck
 * @since 2023/11/6
 */
@Mapper
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
    default Page<OrderInfo> getOrderInfoPageByUserIdAndOrderStatus(Page<OrderInfo> pageParam,Long userId, Integer orderStatus){
        QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        if (orderStatus != null) {
            queryWrapper.eq("order_status", orderStatus);
        }
        queryWrapper.orderByDesc("id");
        return this.selectPage(pageParam,queryWrapper);

    }

    /**
     * 获取订单信息
     * @param orderNo
     * @return
     */
    default OrderInfo getOrderInfoByOrderNo(String orderNo){
        QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_no", orderNo);
        return this.selectOne(queryWrapper);
    }
}
